package com.link510.aitools.core.message;

import android.content.Intent;

import com.link510.aitools.core.constants.FilterConstants;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * 泛型消息
 *
 * @author cqnews
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MessageInfo<T> implements Serializable {

    private static final long serialVersionUID = 7854752185162678504L;

    /**
     * 消息分类
     */
    private Integer type = 0;


    /**
     * 消息状态 -1为常态，0为成功，正常值为错误码
     */
    private Integer state = -1;

    /**
     * 消息说明
     */
    private String message = "物联英卡欢迎您";

    /**
     * 实际内容
     */
    private T content;


    public MessageInfo(String message) {
        this.message = message;
    }


    public static MessageInfo read(Intent intent) {

        try {
            return (MessageInfo) intent.getSerializableExtra(FilterConstants.FILTER_PARAMETER_KEY);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;

    }


}
